package cn.huhst.cas.weisiqian.util;

import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.junit.Test;

public class JSON {

	private ArrayList<String> allKey = new ArrayList<String>();
	private ArrayList<String> allValue = new ArrayList<String>();
	private Logger logger = Logger.getLogger(JSON.class);

	public void put(String key, String value) {
		allKey.add(key);
		allValue.add(value);
	}

	public void putErrorMSG(String msg){
		put("status","error");
		put("msg",msg);
	}
	
	public void putOKMSG(String msg){
		put("status","ok");
		put("msg",msg);
	}
	
	public boolean isEmpty() {
		if (allKey.size() > 0 || allValue.size() > 0) {
			return false;
		} else {
			return true;
		}
	}

	@Override
	public String toString() {
		int count = allKey.size();
		if (allKey.size() > 0 && allValue.size() > 0) {
			String json = "{";
			for (int i = 1; i < count; i++) {
				json += "\"" + allKey.get(i) + "\":\"" + allValue.get(i) + "\",";
			}
			json += "\"" + allKey.get(0) + "\":\"" + allValue.get(0) + "\"}";
			return json;
		} else {
			return "{}";
		}
	}

}
